package com.paipaideli.ui.home.adapter.model;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import com.paipaideli.R;
import com.paipaideli.ui.home.adapter.DocResAdapter;
import com.paipaideli.ui.home.bean.HomeBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * TODO("icons ")
 */

public class HomeIconsModel extends FrameLayout {


    @BindView(R.id.banner_icon_recycle)
    RecyclerView bannerIconRecycle;

    public HomeIconsModel(@NonNull Context context) {
        super(context);
        init(context);
    }

    public HomeIconsModel(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public HomeIconsModel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    List<HomeBean.Data.SysDocRes> values=new ArrayList<>();

    public void setDate(List<HomeBean.Data.SysDocRes> docRes) {
        if(docRes!=null){
            this.values = docRes;
        }
        recycle(values);
    }

    public void recycle(List<HomeBean.Data.SysDocRes> values){
        if(values.size()<5){
            bannerIconRecycle.setLayoutManager(new GridLayoutManager(getContext(),4){
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
        }else if(values.size()==5){
            bannerIconRecycle.setLayoutManager(new GridLayoutManager(getContext(),5){
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
        }else if(values.size() <=8&values.size()>5){
            bannerIconRecycle.setLayoutManager(new GridLayoutManager(getContext(),4){
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
        }else{
            bannerIconRecycle.setLayoutManager(new GridLayoutManager(getContext(),5){
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
        }
        String color="#333333";
        bannerIconRecycle.setAdapter(new DocResAdapter(getContext(), values, "1", "1",color));

    }

    public void init(Context context) {
        View inflate = View.inflate(context, R.layout.item_icon_home, this);
        ButterKnife.bind(inflate);
        bannerIconRecycle.setRecycledViewPool(new RecyclerView.RecycledViewPool());
    }

}
